//
//  HTPopViewViewController.m
//  HTDemo
//
//  Created by meet on 14-3-14.
//  Copyright (c) 2014年 HT. All rights reserved.
//

#import "HTPopViewViewController.h"
#import "HTPopView.h"
#import "HTGuideViewController.h"
@interface HTPopViewViewController ()<HTPopViewDelegate>
@property (nonatomic, strong) NSArray *popItems;
@end

@implementation HTPopViewViewController
{
    BOOL _hasPopViewApeared;
    
}
#pragma mark - 生命周期

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self drawNavigationBar];
    [self drawDisplayImageView];
}

#pragma mark - 绘制视图
- (void)drawNavigationBar
{

    UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
    [item setTitle:@"点我呀!" forState:UIControlStateNormal];
    [item setTitleColor:COLOR_NAVIGATION_ITEM forState:UIControlStateNormal];
    [item addTarget:self action:@selector(rightNavigationBarPressed:) forControlEvents:UIControlEventTouchDown];
    item.tag = YES;
    [item sizeToFit];
    item.showsTouchWhenHighlighted = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:item];
    self.navigationItem.title = @"项目经历";
}

- (void)drawDisplayImageView
{
    UIImageView *displayView = [[UIImageView alloc] initWithFrame:CGRectMake(0, (IS_PHONE_5_OR_LATER)?100:70, Screen_Width,  Screen_Width)];
    displayView.image = [UIImage imageNamed:@"XcodeIcon"];
//    displayView.layer.cornerRadius = Screen_Width/8;
//    displayView.layer.masksToBounds = YES;
    [self.view addSubview:displayView];
}

#pragma mark - 回调函数
- (void)rightNavigationBarPressed:(id)sender
{

    if([[HTPopView popView] superview] == self.view){
        
        [HTPopView dismiss];
    }else{
        HTPopView *popView = [HTPopView popViewWithStringArray:self.popItems _origin:CGPointMake(Screen_Width/2, 0)];
        popView.delegate = self;
        [self.view addSubview:popView];
    }
}

#pragma mark - getter
- (NSArray *)popItems
{
    if(_popItems == nil){
        
        _popItems = @[@"慈安生命汇",@"学舟"];
    }
    return  _popItems;
}

#pragma mark - popView Delegate
- (void)popView:(HTPopView *)popView _itemHasClicked:(NSInteger)itemIndex
{
    NSArray *guideImageNames;
    if(itemIndex == 0){
        
        if(IS_PHONE_5_OR_LATER){
        
            guideImageNames = @[@"cian1",@"cian2",@"cian3"];
        }else{
            
            guideImageNames = @[@"cian1_480",@"cian2_480",@"cian3_480"];
        }
    }
    if(itemIndex == 1){
        if(IS_PHONE_5_OR_LATER){
            
            guideImageNames = @[@"eduBoat1",@"eduBoat2",@"eduBoat3"];
        }else{
            
            guideImageNames = @[@"eduBoat1_480",@"eduBoat2_480",@"eduBoat3_480"];
        }
    }
    
    HTGuideViewController *guideVC = [[HTGuideViewController alloc] init];
    guideVC.guideImageNames = guideImageNames;
    [self presentViewController:guideVC animated:YES completion:^{
        
    }];
}

@end
